package com.inspectortime.webapp.inspector.scheduleRule;

import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;

import com.inspectortime.domain.ScheduleRule;
import com.inspectortime.domain.type.FrequencyType;

public class NonRecurringScheduleRuleValidator extends ScheduleRuleValidator {
	
	public void validate(Object obj, Errors errors) {
		ScheduleRule scheduleRule = (ScheduleRule) obj;
	
		//This shouldn't happen, but better to be safe
		if (scheduleRule.getFrequencyType() != FrequencyType.SINGLE_DAY) {
			errors.reject("addEditScheduleRule.invalid.data");	
		}
		
		ValidationUtils.rejectIfEmpty(errors, "startDate","addEditScheduleRule.singleDay.startDate.required");
		
		super.validate(obj, errors);
		
	}

}
